<%
sel_task_id = session[:selected_task].to_i
special     = session[:selected_special]
#children    = @tasks.select {|t| t.task_id==sel_task_id }
%>

<%= pluralize(@tasks.size, "task")%><br/>

<!-- Buttons -->
<div class="button_bar">
<img src="" width='1' height='15'>
<%= link_to_function('new task', 'add_new_row()', {:onmouseover=>"mover('a')", :onmouseout=>"mover('')", :class=>'button' }) %>
<%= link_to_remote("deadlines",
   {:update => :taskslist,
    :url =>{ :action => :display_deadlines },
    :loading=>"$('loading').show();",
    :success=>"$('loading').hide();"},
   {:class=>'btnlnk'})
%>


<!-- Information on filter -->
<% if(session[:selected_state] != '0' and session[:selected_state] != 'all') -%>
<span class="strong">Filtering by <span class="state <%=session[:selected_state]%>"><%=session[:selected_state]%></span> tasks</span>
<% end -%>

<!-- Loading image -->
<img id="loading" src="/images/loading.gif" style="display:none;">
</div>

<!-- Tools -->
<a href="#" title="display root tasks" onclick="$('loading').show();disp_sub(0);return false;"><img src="/images/sitemap-green.gif"></a>
<a href="#" title="paste to root" onclick="paste(0,'item');return false;"><img src="/images/paste.png"></a>
<a href="#" title="print tasks" onmouseover="mover('print')" onclick="print(0);return false;"><img src="/images/print.png" border="0"></a>
<%=
link_to_remote(image_tag('refresh.gif', :title=>'refresh tasks'),
  {:update => :taskcontent,
   :url =>{ :action => :refresh_task_content },
   :loading=>"$('loading').show();"})
%>

<!-- Selected task -->

<%
if(sel_task_id != 0 and special == '0')
  sel_task = Task.find(sel_task_id)
-%>
<a href="#" title="go up" onclick="$('disp_up').src='/images/loading.gif';disp_sub(<%=sel_task.task_id%>);return false;"><img id="disp_up" src="/images/disp_up.gif"></a>
<%= render(:partial => "task_title", :object => sel_task, :locals=>{:item_name=>'item'}) %>
<a href="#" title="paste in selected task root" onclick="paste(<%=sel_task.id%>,'item');return false;"><img src="/images/paste.png"></a>
<%= link_to_remote(image_tag('bookmark.png', :title=>"bookmark"), {
    :url => {:controller=>'bookmarks', :action=>'create',:task_id=>sel_task.id, :project_id=>sel_task.project_id},
    :success=>"refresh_bookmarks();Element.hide('loading')",
    :loading=>"Element.show('loading')"})
%>

<% end -%>

<!-- Tasks -->

<% if @tasks.size == 0 -%>
<br/>
No tasks. To add a task, click 'New Task'<br/>
<br/>
<% end -%>

<ul id="taskslist" class="sortablelist">
<% 
#by_tag = nil if (defined? by_tag) == nil # default value, so we don't have to pass it every time as :locals
#if(by_tag!=nil) -%>
  <%= render(:partial => "task", :collection => @tasks, :locals=>{:tasks=>@tasks, :item_name=>'item'}) -%>
<%# else -%>
  <%#= render(:partial => "task", :collection => children, :locals=>{:tasks=>@tasks, :item_name=>'item'}) -%>
<%# end %>


<!-- other states -->
<% if session[:selected_state]!="0" -%>
  <%= render(:partial=>'other_state_tasks', :locals=>{:id=>0, :tasks=>@ost}) -%>
<% end -%>
</ul>

<br/>
<br/>

<!-- Tasks done -->

<%= link_to_remote("Display done tasks",
   {:update => :tasksdone,
    :url =>{ :action => :display_tasks_done },
    :loading=>visual_effect('appear', 'loading2'),
    :success=>visual_effect('fade', 'loading2')},
   {:class=>'btnlnk', :id=>'done_link'})
%>
<img id="loading2" src="/images/loading.gif" style="display:none;">
<div id="tasksdone">
	<ul id="taskdoneul" class="mylist"></ul>
</div>

<%= sortable_element('taskslist', {:url => { :action => "order" }}) -%>

